<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>数据源</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div class="ccpui-tablesize" style="padding:10px;">
    <table id="dataSource" lay-filter="dataSource"></table>
</div>
<script type="text/html" id="dataSourceToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                <span>添加</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="export">
                <i class="layui-icon layui-icon-export"></i>
                <span>导出</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="import">
                <i class="layui-icon layui-icon-download-circle"></i>
                <span>导入</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
        </div>
        <form class="layui-form" action="" style="margin-top:10px" lay-filter="source">
            <div class="table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">名称 </label>
                    <input type="text" name="Q_name_SL" id="name" class="layui-input filter-value" placeholder="名称"
                           autocomplete="off"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">别名 </label>
                    <input type="text" name="Q_alias_SL" id="alias" class="layui-input filter-value" placeholder="别名"
                           autocomplete="off"/>
                </div>
            </div>
        </form>
    </div>
</script>

<script type="text/html" id="manageBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'jquery', 'form', 'tree', 'commons', 'common', 'totalFilter', 'setter'], function () {
        var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,$=layui.jquery,
            common = layui.common, totalFilter = layui.totalFilter, form = layui.form;
        var tableH = 'full-70';
        var tableH = commons.tabHeight(tableH);
        common.tableSort("dataSource");
        //渲染表格
        table.render({
            elem: '#dataSource'
            , cellMinWidth: 80
            , title: '数据源表'
            , defaultToolbar: []
            , height: tableH
            , url: serverPath.systemPath + setter.sysLinkPath + 'dataSource/list'
            , toolbar: '#dataSourceToolsBar'
            , page: true
            , autoSort: false
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'name', title: '名称', sort: true,align: 'center'}
                , {field: 'alias', title: '别名', sort: true, align: 'center'}
                , {field: 'dbType', title: '数据库类型', align: 'center'}
                , {
                    field: 'initOnStart', title: '初始化容器',align: 'center',
                    templet: function (d) {
                        if (d.initOnStart == 1) {
                            return '是';
                        }
                        return '否';
                    }
                }
                , {
                    field: 'enabled', title: '是否生效', sort: true, align: 'center',
                    templet: function (d) {
                        if (d.enabled == 1) {
                            return '是';
                        }
                        return '否';
                    }
                }
                , {fixed: 'right', title: '管理', toolbar: '#manageBar', width: 150, align: 'center'}
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });
        totalFilter.init('dataSource');
        table.on('toolbar(dataSource)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'export':
                    if (data.length == 0) {
                        layer.confirm('还没有选择，是否导出全部？', {
                            btn: ['确定', '取消'] //按钮
                        }, function (index) {
                            layer.close(index);
                            var url = serverPath.systemPath + setter.sysLinkPath + 'dataSource/exportXml';
                            window.location.href = url;
                        });
                    } else {
                        layer.confirm('确定导出吗？', {
                            btn: ['是', '否'] //按钮
                        }, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            var tableIds = ids.join(',');
                            var url = serverPath.systemPath + setter.sysLinkPath + 'dataSource/exportXml?tableIds=' + tableIds;
                            window.location.href = url;
                        });
                    }
                    break;
                case 'import':
                    layer.open({
                        type: 2,
                        title: "导入",
                        shade: 0.3,
                        area: ['400px', '300px'],
                        content: serverPath.systemPath + setter.sysLinkPath + "dataSource/view/import"
                        ,end:function () {
                            table.reload('dataSource', {
                                page: {
                                    curr: 1
                                }
                            });
                            totalFilter.init('dataSource');
                        }
                    })
                    break;
                case 'query':
                    common.tableConditionRender("dataSource", "source", {where: {}}, false);
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        title: "添加",
                        shade: 0.3,
                        area: ['600px', '500px'],
                        content: serverPath.systemPath + setter.sysLinkPath + "dataSource/view/add"
                    })
                    break;
                case 'reset':
                    common.tableConditionRender("dataSource", "source", {where: {}}, true);
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(dataSource)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确定删除当前数据吗？', function (index) {
                        var selId = obj.data.id;
                        var t_date = {};
                        t_date.id = selId;
                        $.ajax({
                            url: serverPath.systemPath + setter.sysLinkPath + "dataSource/del",
                            data: t_date,
                            dataType: 'json',
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                table.reload('dataSource', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                totalFilter.init('dataSource');
                            }
                        });
                    });
                    break;
                case 'edit':
                    var oid = obj.data.id;
                    layer.open({
                        type: 2
                        , title: "编辑"
                        , content: serverPath.systemPath + setter.sysLinkPath +'dataSource/view/edit?dataSourceId=' + oid
                        , area: ['600px', '500px']
                    });
                    break;
            }
        });
    });
</script>
</body>
</html>